﻿using Exam.DBHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exam.DAO.ExtendDAO
{
    public class ContentType
    {
        SQLHelper sqlhelper = new SQLHelper();
        public List<Exam.Model.ExtentionModels.ExContentType> GetTypeList(string ModalityID, string ProductID, string TypeName, string IsActive, string orderName, bool asc, int pagestart, int pagesize, out int totalcount)
        {

            StringBuilder builder = new StringBuilder("select ContentType.*,Modality.ModalityName,Product.ProductName from ContentType left join Modality on ContentType.ModalityID=Modality.ModalityID left join Product on ContentType.ProductID=Product.ProductID  where 1=1 ");
            if (!string.IsNullOrEmpty(ModalityID))
            {
                builder.Append(" and  ContentType.ModalityID='");
                builder.Append(ModalityID);
                builder.Append("'");
            }
            if (!string.IsNullOrEmpty(ProductID))
            {
                builder.Append(" and  ContentType.ProductID='");
                builder.Append(ProductID);
                builder.Append("'");
            }
            if (!string.IsNullOrEmpty(TypeName))
            {
                builder.Append(" and ContentType.TypeName like N'%");
                builder.Append(TypeName);
                builder.Append("%'");
            }
            if (IsActive != "-1")
            {
                builder.Append(" and ContentType.IsActive=");
                builder.Append(IsActive);
            }

            if (!string.IsNullOrEmpty(orderName))
            {
                builder.Append(" order by ");
                builder.Append(orderName);
                if (asc)
                {
                    builder.Append(" asc");
                }
                else
                {
                    builder.Append(" desc");
                }
            }
            return sqlhelper.GetEntities<Model.ExtentionModels.ExContentType>(builder.ToString(), pagestart, pagesize, out totalcount);

        }
    }
}
